package criterios;

import domain.IP;

public abstract class PorSubred extends Criterio {

	private String subred;

	public PorSubred(String subred) {
		super();
		this.subred = subred;
	}

	protected IP obtenerIP(IP ip) {
		String[] parts = this.getSubred().split("\\.");
		return new IP(parsear(parts[0], ip.getFstOct()), parsear(parts[1],
				ip.getSndOct()), parsear(parts[2], ip.getTrdOct()), parsear(
				parts[3], ip.getFthOct()));
	}

	private int parsear(String string, int numero) {
		if (string.equals("*")) {
			return numero;
		} else {
			return Integer.parseInt(string);
		}
	}

	public String getSubred() {
		return subred;
	}

	public void setSubred(String subred) {
		this.subred = subred;
	}
}
